package com.magenta.maxoptra.gis.commons;

import java.util.Arrays;

/**
 * Triple of elements.
 * @author ivictus
 *
 * @param <First>
 * @param <Second>
 * @param <Third>
 * 
 * @see #toArray()
 */
public class Triple<First, Second, Third> {
    private final First first;
    private final Second second;
    private final Third third;
    
    /**
     * Default constructor.
     * @param first element.
     * @param second element.
     * @param third element.
     */
	public Triple(First first, Second second, Third third) {
		this.first = first;
		this.second = second;
		this.third = third;
	}

	public First getFirst() {
		return first;
	}

	public Second getSecond() {
		return second;
	}

	public Third getThird() {
		return third;
	}

	@Override
	public int hashCode() {
		return Arrays.hashCode(toArray());
	}

	@Override
	public boolean equals(Object obj) {
		return (obj instanceof Triple) && Arrays.equals(toArray(), ((Triple) obj).toArray());
	}

	@Override
	public String toString() {
		StringBuilder info = new StringBuilder();
		info.append('{').append(first).append(',').append(second).append(',').append(third).append('}');
		return info.toString();
	}
	
	/**
	 * @return triple as array.
	 */
	public Object[] toArray() {
		return new Object[] {first, second, third};
	}
	
	public static<F, S, T> Triple<F, S, T> generate(Pair<F, S> pair, T t) {
		return new Triple<F, S, T>(pair.getFirst(), pair.getSecond(), t);
	}
	public static<F, S, T> Triple<F, S, T> generate(F f, Pair<S, T> pair) {
		return new Triple<F, S, T>(f, pair.getFirst(), pair.getSecond());
	}
	public static<F, S, T> Triple<F, S, T> generate(F f, S s, T t) {
		return new Triple<F, S, T>(f, s, t);
	}
	
}
